/* ************************************************************ */
/* **************** MAIN PROGRAM - MODULES ******************** */

#define MAVLINK10
//#undef MAVLINK10

//#define DEBUG_FRSKY

/* **********************************************/
/* ***************** INCLUDES *******************/
// AVR Includes
#include <FastSerial.h>
#include <AP_Common.h>
#include <AP_Math.h>
#include <math.h>
#include <inttypes.h>
#include <avr/pgmspace.h>
// Get the common arduino functions
#if defined(ARDUINO) && ARDUINO >= 100
	#include "Arduino.h"
#else
	#include "wiring.h"
#endif
#include <GCS_MAVLink.h>

#include "config.h"
#include "OSD_Vars.h"
#include <SendOnlySoftwareSerial.h> //Same as SoftwareSerial, but send only data. Used to send data to MinimOSD


/* *************************************************/
/* ***************** DEFINITIONS *******************/
#define TELEMETRY_SPEED_APM      57600  // How fast our MAVLink telemetry is coming to Serial port
#define TELEMETRY_SPEED_FR_SKY    9600
#ifndef __AVR_ATmega328P__
#error Only ATmega328P board is supported
#endif

// Objects and Serial definitions
FastSerialPort0(Serial);
SendOnlySoftwareSerial sendTelemetry(9, true);

/* **********************************************/
/* ***************** SETUP() *******************/

void setup() 
{

  Serial.begin(TELEMETRY_SPEED_APM);
  mavlink_comm_0_port = &Serial;
  
  sendTelemetry.begin(TELEMETRY_SPEED_FR_SKY);

  delay(500);

} // END of setup();



/* ***********************************************/
/* ***************** MAIN LOOP *******************/

void loop() 
{  
  #if !defined(DEBUG_FRSKY)
  read_mavlink();
  #endif
   
  update_FrSky();  
}


